<%--
 *  File:    UserSummary.jsp
 *  @Author: Langerwang 
 *  Date:    2001/11/4
 *
 *  Copyright (C) 2000 - 2001 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>



<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>

<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.UserSelectPop");  
%>

<% //--------------------------------------  variant and initialization --%>
<%
	String strModuleName = "UPM";
  	String strTableName = "ovuser";
	
%>



<%
  	//get current userinfo
  	HashMap CurUserInfo = (HashMap)session.getAttribute("userinfo");
  	Integer nCurOrgId = (Integer)CurUserInfo.get("orgid");
  	String strCurUserName = (String)CurUserInfo.get("username");
  	Integer nCurUserId = (Integer)CurUserInfo.get("userid");
  	String isPrimaryAdmin = (String)CurUserInfo.get("isprimaryadmin");
  	if(isPrimaryAdmin == null)
  	{
    	isPrimaryAdmin = "";
  	} 
  	//give permission
  	boolean bCanUpdatePrimaryAdmin = true;
  	if(!isPrimaryAdmin.equalsIgnoreCase("Y"))
  	{
    	bCanUpdatePrimaryAdmin = false;
  	} 
%>

<% //--------------------------------------  include files list --%>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>


<html>
<head>
<title>UserSelectPop</title>
<PageFlow:CheckPageFlow pageName="usersummarypop"/>
<%@ include file="/inc/InitEdit.inc" %>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="../js/FuncLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>

<% //--------------------------------------  output variant from pageflow --%>
<%
  	String orgname = (String)CurUserInfo.get("orgname");

  	Integer nOrgId = (Integer)pageContext.getAttribute("orgid");
  	Vector userSummary = (Vector)pageContext.getAttribute("usersummary");
  	if(userSummary == null)
    	userSummary = new Vector();
%>
<script>
function clickUser(id,employeename,name)
{
  document.usersummaryform.userid.value = id;
  document.usersummaryform.employeename.value = employeename;
  document.usersummaryform.username.value = name;
}

function page_delete()
{
  var uid = document.usersummaryform.userid.value;
  var ispaval = document.usersummaryform.ispa.value; 
  if(uid == null || uid.length == 0 || uid == "" || uid == "-1")
    return;
  if(uid == "<%=JspHelper.filterNull( nCurUserId )%>")
  {
    alert("<%= message.getMessageDesc("CAN_NOT_DEL_IT") %>");
    return;
  }
  if(ispaval == "Y" || ispaval == "y")
  {
    alert("<%= message.getMessageDesc("NO_RIGHT") %>");
    return;
  }  
  var flag = confirm("<%= message.getMessageDesc("ARE_YOU_SURE_DEL") %>");
  if(!flag)
    return;
  document.usersummaryform.actionname.value = "delete";
  isRunning = true;
  document.usersummaryform.submit();
}
function page_edit()
{
  var uid = document.usersummaryform.userid.value;
  if(uid == null || uid.length == 0 || uid == "" || uid == "-1")
    return;
  parent.down.location.href = "UserEdit.jsp?<%= OvalTools.randomURL() %>&userid=" + uid + "&languagecode=<%= strLanguageCode %>&orgid=" + "<%=JspHelper.filterNull( nOrgId )%>";
}
function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(usersummaryform,actionvalue,orderbyname);
  editform.action = "UserSelectPop.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}
function page_accreditinfo()
{
  var uid = document.usersummaryform.userid.value;
  if(uid == null || uid.length == 0 || uid == "" || uid == "-1")
      return;
  parent.down.location.href ="UserAuthorityInfo.jsp?<%= OvalTools.randomURL() %>&userid=" + uid;     
}
function page_userauthoritycondition()
{
  var uid = document.usersummaryform.userid.value;
  if(uid == null || uid.length == 0 || uid == "" || uid == "-1")
     return;
  parent.down.location.href ="UserAuthorityCondition.jsp?<%= OvalTools.randomURL() %>&userid=" + uid;
}
function page_finish()
{   var id =usersummaryform.userid.value;
    var name = usersummaryform.username.value;
    var employeename = usersummaryform.employeename.value;
   

    opener.page_setUser(id,name,employeename);
 
   
    window.close();
}
function page_cancel()
{
    window.close();
}
</script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

	<% //--------------------------------------  hidden form variant --%>
	<form name="usersummaryform" method="post" action="../../Dispatcher"  target="_parent">
    <input type="hidden" name="pagename" value="usersummary">
    <input type="hidden" name="actionname">   
    <custom:hidden property="orgid"/>

	<% //--------------------------------------  page location --%>
	
	
	<table width="100%" cellspacing="0" cellpadding="0" border="0">
    <tr> 
    	<td valign="top"> 
        	<table width="100%" border="0" cellspacing="0">
          	<tr> 
            	<td class="summary_top" ></td>
          	</tr>
        	</table>
        	<table width="100%" border="0" cellspacing="0" cellpadding="0">
        	
            <td>
            	<table>
            		<%@ include file="/inc/SummarySearch.inc" %>
            	</table>
            </td>
          </tr>
        </table>
        
        <table border="1" cellspacing="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" align="center" width="100%" cellpadding="0">
        
        <% //--------------------------------------  summary header --%>
        <tr bgcolor="#ACBCCA" class="deepblue-left"> 
        	<td width="5%" class="title_center">&nbsp;</td>
            <td width="16%" class="title_center"><a href="javascript:page_summary('orderby','username')"><%= label.getLabelName("L_UserCode") %></a></td>
            <td width="10%" class="title_center"><a href="javascript:page_summary('orderby','employeename')"><%= label.getLabelName("L_username") %></a></td>
            <td width="14%" class="title_center"><a href="javascript:page_summary('orderby','passwordstartdate')"><%= label.getLabelName("L_PasswordStartDate") %></a></td>
            <td width="15%" class="title_center"><a href="javascript:page_summary('orderby','passwordexpiredate')"><%= label.getLabelName("L_PasswordExpireDate") %></a></td>
            <td 			class="title_center"><a href="javascript:page_summary('orderby','email')"><%= label.getLabelName("L_Email") %></a></td>
            <td width="18%" class="title_center"><a href="javascript:page_summary('orderby','canupdatepassword')"><%= label.getLabelName("L_CanUpdatePassword") %></a></td>
            <td width="7%" class="title_center"><a href="javascript:page_summary('orderby','statusname')"><%= label.getLabelName("L_Status") %></a></td>
       	</tr>
        
        <% //--------------------------------------  default value definition --%>
        <%
        	int i = 0;
            String strClassType = new String();   
            Integer nDefaultUserId = new Integer(-1); 
            String strIsPrimaryAdmin = "";
            boolean bHasChecked = false;  
            String nDefaultUserName ="";   
            String nDefaultEmployeeName ="";   
      	%>
        
        <% //--------------------------------------  loop results --%>
        <logic:iterate id="usersum" collection="<%= userSummary %>">                      
        <%
        	HashMap userMap = (HashMap)pageContext.getAttribute("usersum"); 
            String strUserName = (String)userMap.get("username");  
            String userIsPrimaryAdmin = (String)userMap.get("isprimaryadmin");
            String strEmployeeName = (String)userMap.get("employeename");
            String strIsDisabled = new String("");
            String strIsChecked = new String("");
            if(i%2 == 1)
            {
              	strClassType = "td-listrom";
            }else{                    
              	strClassType = "";
            }
            if(!bCanUpdatePrimaryAdmin && "Y".equalsIgnoreCase(userIsPrimaryAdmin) && nCurOrgId.equals((Integer)userMap.get("orgid")) )
            {
               strIsDisabled = new String(" Disabled ");
               userMap.put("userid","-1");
            } 
            else if(!bHasChecked)
            {
            	  strIsChecked = "Checked";                       
              	bHasChecked = true;            
              	nDefaultUserId = (Integer)(userMap.get("userid"));       
            	  strIsPrimaryAdmin = (String)(userMap.get("isprimaryadmin"));
            	  nDefaultUserName = strUserName;
            	  nDefaultEmployeeName = strEmployeeName;
            }
            i++;                         
          %>
          
     	<tr onMouseOver="this.className='tr-over'" onMouseOut="this.className='<%=JspHelper.filterNull( strClassType )%>'"  onClick="javascript:radiotrue('user<%=JspHelper.filterNull( i )%>');clickUser('<%=JspHelper.filterNull( userMap.get("userid") )%>','<%=JspHelper.filterNull( userMap.get("employeename") )%>','<%=JspHelper.filterNull( userMap.get("username") )%>');" class="<%=JspHelper.filterNull( strClassType )%>"> 
        	<td width="5%" class="<%=JspHelper.filterNull( strClassType )%>">
            	<input type="radio" id="user<%=JspHelper.filterNull( i )%>"name="checkuser" <%=JspHelper.filterNull( strIsDisabled )%> value=<%=JspHelper.filterNull( userMap.get("userid") )%> class="checkbox" <%=JspHelper.filterNull( strIsChecked )%>>
            </td>
            <td width="16%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("username") )%></td>
            <td width="10%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("employeename") )%></td>
            <td width="14%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%= OvalTools.dateToString(userMap.get("passwordstartdate"),(String)session.getAttribute("dateformat")) %></td>
            <td width="15%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%= OvalTools.dateToString(userMap.get("passwordexpiredate"),(String)session.getAttribute("dateformat")) %></td>
            <td class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("email") )%></td>
            <td width="18%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("canupdatepassword") )%></td>
            <td width="7%" class="<%=JspHelper.filterNull( strClassType )%>">&nbsp;<%=JspHelper.filterNull( userMap.get("statusname") )%></td>
     	</tr>
        </logic:iterate>                   
        
        <% //--------------------------------------  default value --%>       
        <input type="hidden" name="userid" value="<%=JspHelper.filterNull( nDefaultUserId )%>">
        <input type="hidden" name="username" value="<%=JspHelper.filterNull( nDefaultUserName )%>">
        <input type="hidden" name="employeename" value="<%=JspHelper.filterNull( nDefaultEmployeeName )%>">

        <% //--------------------------------------  flipping page --%>
    	<%@ include file="/inc/SummaryAction.inc" %>
          
        </table>
        
        <% //--------------------------------------  page operation button --%>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        	<tr> 
            	<td class="summary_top" ></td>
          	</tr>
          	<tr> 
            	<td class="td_center">
            		<a onclick="page_finish()"><custom:button type="1" label="L_Finish" imgsrc="edit.gif" border="0" style="width:60"/></a>
            		<a onclick="page_cancel()"><custom:button type="1" label="L_Cancel" imgsrc="delete.gif" border="0" style="width:60"/></a>
            	</td>
          	</tr>
        </table>
        
  	</td>
</tr>
</table>
</form>
</body>
</html>


